#include "carpospage.h"
#include<QPainter>
#include<QPixmap>
#include"mydata.h"

CarPosPage::CarPosPage(QWidget *parent) : QWidget(parent)
{

}

void CarPosPage::paintEvent(QPaintEvent *)
{
    QPainter painter;
    QPixmap pix(":/Image/RoadMap.jpg");

    QFont font("Times",16,QFont::Bold);
    QPen pen;
    pen.setColor(Qt::black);


    painter.begin(&pix);
    painter.setFont(font);
    painter.setPen(pen);

    QPixmap carImg(":/Image/car.png");
    int carCount = MyData::getObject()->carCount();
    for(int i=0;i<carCount;i++)
    {
        Car *car = MyData::getObject()->getCar(i);
        painter.drawPixmap(car->x, car->y,30,30,carImg);
        painter.drawText(car->x+8,car->y+24,QString("%1").arg(car->id));
    }
    painter.end();

    painter.begin(this);
    painter.drawPixmap(0,0,width(),height(),pix);
    painter.end();
}
